﻿@model IEnumerable<Core.Models.Comment>
@{
    var list = Model.ToList();               
}
@for (int i = 0; i < list.Count(); i++)
{
    var item = list[i];
    if (i % 2 > 0)
    {
        <div class="primary_item_comment odd" id="comment-@item.Id">
            <div class="primary_item_comment_content">
                @Html.DisplayFor(modelItem => item.Content)
            </div>
            <div class="primary_item_comment_info">
                From: @item.Email | First Name: @item.FirstName | Last Name: @item.LastName<br />
                @*@Html.ActionLink(" >>Delete", "Delete", "Comment", new { id = item.Id }, "")*@
                <a href="#" class="DeleteLink" data-id="@item.Id">Delete Comment</a>    
            </div>
        </div>
    }
    else
    {
        <div class="primary_item_comment even" id="comment-@item.Id">
            <div class="primary_item_comment_content">
                @Html.DisplayFor(modelItem => item.Content)
            </div>
            <div class="primary_item_comment_info">
                From: @item.Email | First Name: @item.FirstName | Last Name: @item.LastName<br />
                @*@Html.ActionLink(" >>Delete", "Delete", "Comment", new { id = item.Id }, "")*@
                <a href="#" class="DeleteLink" data-id="@item.Id">Delete Comment</a>    
            </div>
        </div>
    }
}

<script type="text/javascript">
    $(function () {
        // Document.ready -> link up remove event handler
        $(".DeleteLink").click(function () {
            // Get the id from the link
            var recordToDelete = $(this).attr("data-id");
            if (recordToDelete != '') {                
                $.ajax({
                    type: "POST", //Phương thức gửi request là POST hoặc GET
                    data: "id=" + recordToDelete, //tham số gửi kèm
                    dataType: "Json", //kiểu dữ liệu trả về, mặc định là text
                    url: "/Comment/Delete", //Đường dẫn tới nơi xử lý request ajax
                    success: function (data) { //hàm gọi về khi thực hiện thành công
                        // Successful requests get here
                        // Update the page elements
                        $('#comment-' + data).fadeOut('slow');
                    }
                });
            }
        });
    });
</script>
